package Chuong06;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class Bai01_Oval extends Thread{
	JPanel canvas;
	public Bai01_Oval(JPanel c){
		canvas = c;
	}
	
	public void run(){
		int w = canvas.getSize().width;
		int h = canvas.getSize().height;
		while(true){
			Graphics g = canvas.getGraphics();
			
			g.setColor(Color.BLACK);
			g.drawLine(w/2, 0, w/2, h);
			
			Color c = new Color((int)(255.0*Math.random()),
								(int)(255.0*Math.random()),
								(int)(255.0*Math.random()));
			g.setColor(c);
			int x = (int)((float)w*Math.random()) + w/2,
				y = (int)((float)h*Math.random());
			g.drawOval(x, y, 20, 20);
			try{
				Thread.sleep(10);
			}
			catch(InterruptedException e){}

		}
	}
}
